home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 February / EnigmA AMIGA RUN 15 (1997)(G.R. Edizioni)(IT)[!][issue 1997-02][PLANET CD V].iso / enigma / earcd / emula / arosdv19.lha / AROS / exec / createpool.c < prev    next >
C/C++ Source or Header  |  1996-10-24  |  3KB  |  125 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: createpool.c,v 1.6 1996/10/24 15:50:47 aros Exp $
  4.     $Log: createpool.c,v $
  5.     Revision 1.6  1996/10/24 15:50:47  aros
  6.     Use the official AROS macros over the __AROS versions.
  7.  
  8.     Revision 1.5  1996/10/19 17:09:02  aros
  9.     Include <aros/machine.h> over "machine.h"
  10.     Fixed a type in the docs
  11.  
  12.     Revision 1.4  1996/08/13 13:56:00  digulla
  13.     Replaced AROS_LA by AROS_LHA
  14.     Replaced some AROS_LH*I by AROS_LH*
  15.     Sorted and added includes
  16.  
  17.     Revision 1.3  1996/08/01 17:41:09  digulla
  18.     Added standard header for all files
  19.  
  20.     Desc:
  21.     Lang:
  22. */
  23. #include "exec_intern.h"
  24. #include <aros/libcall.h>
  25. #include <clib/alib_protos.h>
  26. #include <aros/machine.h>
  27. #include "memory.h"
  28.  
  29. #define NEWLIST(l) \
  30. ((l)->lh_Head=(struct Node *)&(l)->lh_Tail, \
  31.  (l)->lh_Tail=NULL,                         \
  32.  (l)->lh_TailPred=(struct Node *)(l))
  33.  
  34. /*****************************************************************************
  35.  
  36.     NAME */
  37.     #include <exec/memory.h>
  38.     #include <clib/exec_protos.h>
  39.  
  40.     AROS_LH3(APTR, CreatePool,
  41.  
  42. /*  SYNOPSIS */
  43.     AROS_LHA(ULONG, requirements, D0),
  44.     AROS_LHA(ULONG, puddleSize,   D1),
  45.     AROS_LHA(ULONG, threshSize,   D2),
  46.  
  47. /*  LOCATION */
  48.     struct ExecBase *, SysBase, 116, Exec)
  49.  
  50. /*  FUNCTION
  51.     Create a private pool for memory allocations.
  52.  
  53.     INPUTS
  54.     requirements - The type of the memory
  55.     puddleSize   - The number of bytes that the pool expands
  56.                if it is too small.
  57.     threshSize   - Allocations beyond the threshSize are given
  58.                directly to the system. threshSize must be
  59.                smaller than the puddleSize.
  60.  
  61.     RESULT
  62.     A handle for the memory pool or NULL if the pool couldn't
  63.     be created
  64.  
  65.     NOTES
  66.  
  67.     EXAMPLE
  68.     \* Get the handle to a private memory pool *\
  69.     po=CreatePool(MEMF_ANY,16384,8192);
  70.     if(po!=NULL)
  71.     {
  72.         \* Use the pool *\
  73.         UBYTE *mem1,*mem2;
  74.         mem1=AllocPooled(po,1000);
  75.         mem2=AllocPooled(po,2000);
  76.         \* Do something with the memory... *\
  77.  
  78.         \* Free everything at once *\
  79.         DeletePool(po);
  80.     }
  81.  
  82.     BUGS
  83.  
  84.     SEE ALSO
  85.     DeletePool(), AllocPooled(), FreePooled()
  86.  
  87.     INTERNALS
  88.  
  89.     HISTORY
  90.     16-10-95    created by m. fleischer
  91.  
  92. ******************************************************************************/
  93. {
  94.     AROS_LIBFUNC_INIT
  95.  
  96.     struct Pool *pool=NULL;
  97.  
  98.     /* puddleSize must not be smaller than threshSize */
  99.     if(puddleSize>=threshSize)
  100.     {
  101.     /* Round puddleSize up to be a multiple of MEMCHUNK_TOTAL. */
  102.     puddleSize=(puddleSize+MEMCHUNK_TOTAL-1)&~(MEMCHUNK_TOTAL-1);
  103.  
  104.     /*
  105.         Allocate memory for the Pool structure using the same requirements
  106.         as for the whole pool (to make it shareable, residentable or
  107.         whatever is needed).
  108.     */
  109.     pool=(struct Pool *)AllocMem(sizeof(struct Pool),requirements);
  110.     if(pool!=NULL)
  111.     {
  112.         /* Clear the lists */
  113.         NEWLIST((struct List *)&pool->PuddleList);
  114.         NEWLIST((struct List *)&pool->BlockList );
  115.  
  116.         /* Set the rest */
  117.         pool->Requirements=requirements;
  118.         pool->PuddleSize  =puddleSize;
  119.         pool->ThreshSize  =threshSize;
  120.     }
  121.     }
  122.     return pool;
  123.     AROS_LIBFUNC_EXIT
  124. } /* CreatePool */
  125.